<?php  
/**************************************************/
## Class Name - Model_ModuleUser (Contains all the functions related admin and sub-admon permissions)
## Created By - Techmodi (19/08/2011)
/**************************************************/

class Model_ModuleUser extends Database
{
	## Constructor
	function Model_ModuleUser() {
		$this->moduleuser = MODULEUSER;
		$this->modules= MODULES;
		
		$this->Database();
	}	
	
	function getStatusValueByUserIdAndModuleId($userId, $moduleId) {
		$fields=array('perm_status');
		$tables=array($this->moduleuser);
		$where=array("user_id='".$userId."'", "module_id='".$moduleId."'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;
	}
	function getModuleHelpText($moduleId) {
		$fields=array();
		$tables=array($this->modules);
		$where=array("module_id='".$moduleId."'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;
	}
	function editModuleHelpTextById($array, $moduleId)	{
		$this->UpdateData($this->modules,$array,"module_id",$moduleId,0);
	}
	
	function getModuleUserValueByUserIdWithActiveStatus($userId) {
		$fields=array();
		$tables=array($this->moduleuser);
		$where=array("user_id='".$userId."'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array('module_user_id'), $group=array(),$limit = "",0,0);
		$result= $this->FetchAll($result1);
		return $result;
	}
	
	function addModuleUserValue($array)	{
		$this->InsertData($this->moduleuser,$array);
	}
		
	function editModuleUserValueById($array, $moduleUserId)	{
		$this->UpdateData($this->moduleuser,$array,"module_user_id",$moduleUserId,0);
	}
	
	function deleteModuleUserValueById($moduleUserId) {
		$this->DeleteData($this->moduleuser,"module_user_id",$moduleUserId);
	}
	
	function deleteModuleUserValueByUserId($userId)	{
		$sql= "DELETE FROM ".$this->moduleuser." WHERE user_id=".$userId;
		$res= $this->ExecuteQuery($sql);
	}
	
	function getAllMasterModules() {
		$fields=array();
		$tables=array($this->modules);
		$where=array();
		$result1 = $this->SelectData($fields,$tables, $where, $order = array("module_id ASC"), $group=array(),$limit = "",0,0);
		$result= $this->FetchAll($result1);
		return $result;
	}
	
	## Update faq status with multiple ids
	function updateModulesStatusIn($ids) {
		$sql = "UPDATE ".$this->modules." SET module_status='1' WHERE module_id IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	## Update faq status with multiple ids
	function updateModulesStatusNotIn($ids) {
		$sql = "UPDATE ".$this->modules." SET module_status='0' WHERE module_id NOT IN (".$ids.")";
		$result1= $this->ExecuteQuery($sql);	 
		
	}
	
	function getAllMasterActiveModules() {
		$fields=array();
		$tables=array($this->modules);
		$where=array("module_status='1'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array('module_id ASC'), $group=array(),$limit = "",0,0);
		$result= $this->FetchAll($result1);
		return $result;
	}
	
	function getModulePermissionStatusByUserId($userId, $moduleId)
	{
		$fields=array('perm_status');
		$tables=array($this->moduleuser);
		$where=array("user_id='".$userId."'", "module_id='".$moduleId."'");
		$result1 = $this->SelectData($fields,$tables, $where, $order = array(), $group=array(),$limit = "",0,0);
		$result= $this->FetchRow($result1);
		return $result;
	}
	
	
}